Skip to content

fix: HTML export/parse round trip ignoring empty blocks (BLO-873) - #2931

Merged
matthewlipski merged 2 commits into
mainfrom
parse-preserve-white-space
Aug 4, 2026
Merged

fix: HTML export/parse round trip ignoring empty blocks (BLO-873)#2931
matthewlipski merged 2 commits into
mainfrom
parse-preserve-white-space

Conversation

@matthewlipski

@matthewlipski matthewlipski commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR fixes empty paragraphs getting dropped when running to round trip of blocksToHTMLLossy -> tryParseHTMLToBlocks. The fix is to add a Unicode object replacement character to empty blocks' inline content elements when exporting to lossy HTML. This causes the blocks to be parsed instead of ignored without introducing any other changes in behaviour. Markdown export/parse works the same, and the character don't affect rendering the lossy HTML. For good measure though, the character is also stripped when parsing HTML to ensure full round-trip consistency.

Closes #986

Rationale

Dropping empty blocks is a loss of information from the original document that I believe is never desirable for consumers. For this reason, Ive also opted to not make this behaviour configurable.

Changes

See above.

Impact

N/A

Testing

Added unit test case and updated existing HTML export snapshots.

Screenshots/Video

N/A

Checklist

  • Code follows the project's coding standards.
  • Unit tests covering the new feature have been added.
  • All existing tests pass.
  • The documentation has been updated to reflect the new feature

Additional Notes

N/A

Summary by CodeRabbit

  • Bug Fixes

    • Preserved empty paragraphs and other empty inline-content blocks during HTML export and re-import.
    • Prevented blank blocks between content from being dropped in round trips.
    • Prevented internal placeholder characters from appearing in Markdown or parsed content.
  • Tests

    • Added coverage for HTML containing an empty paragraph between two populated paragraphs.

@matthewlipski
matthewlipski requested a review from nperez0111 July 29, 2026 15:45
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blocknote Ready Ready Preview Aug 4, 2026 9:40am
blocknote-website Ready Ready Preview Aug 4, 2026 9:40am

Request Review

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The HTML serializer now preserves empty inline blocks with an object replacement character. The HTML parser and Markdown exporter remove this marker. Export coverage includes an empty paragraph between two populated paragraphs.

Changes

Empty inline HTML preservation

Layer / File(s) Summary
Serializer marker and block handling
packages/core/src/api/exporters/html/util/serializeBlocksExternalHTML.ts
The serializer exports EMPTY_BLOCK_PLACEHOLDER for empty inline-content blocks, except code blocks and container-like nodes.
Import and Markdown marker cleanup
packages/core/src/api/parsers/html/parseHTML.ts, packages/core/src/api/exporters/markdown/markdownExporter.ts
The HTML parser removes the marker recursively. Markdown conversion removes the marker before conversion.
Empty paragraph export coverage
tests/src/unit/core/formatConversion/export/exportTestInstances.ts
The export cases include an empty paragraph between “Before” and “After”.

Estimated code review effort: 3 (Moderate) | ~15–30 minutes

Possibly related PRs

Suggested reviewers: nperez0111

Poem

A rabbit marks an empty line,
With one small sign in Unicode design.
HTML carries it through the way,
Then parsers clear the mark away.
“Before” and “After” stay in place.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the fix for empty blocks lost during HTML export and parse round trips.
Description check ✅ Passed The description covers the required sections, explains the rationale and impact, and documents testing; documentation remains unchecked but is non-critical.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch parse-preserve-white-space

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://TypeCellOS.github.io/BlockNote/pr-preview/pr-2931/

Built to branch gh-pages at 2026-08-04 09:53 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@nperez0111

Copy link
Copy Markdown
Contributor

We'll need to get this passing again before merging

@pkg-pr-new

pkg-pr-new Bot commented Aug 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/@blocknote/ariakit@2931

@blocknote/code-block

npm i https://pkg.pr.new/@blocknote/code-block@2931

@blocknote/core

npm i https://pkg.pr.new/@blocknote/core@2931

@blocknote/mantine

npm i https://pkg.pr.new/@blocknote/mantine@2931

@blocknote/react

npm i https://pkg.pr.new/@blocknote/react@2931

@blocknote/server-util

npm i https://pkg.pr.new/@blocknote/server-util@2931

@blocknote/shadcn

npm i https://pkg.pr.new/@blocknote/shadcn@2931

@blocknote/xl-ai

npm i https://pkg.pr.new/@blocknote/xl-ai@2931

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/@blocknote/xl-docx-exporter@2931

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/@blocknote/xl-email-exporter@2931

@blocknote/xl-multi-column

npm i https://pkg.pr.new/@blocknote/xl-multi-column@2931

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/@blocknote/xl-odt-exporter@2931

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/@blocknote/xl-pdf-exporter@2931

commit: 1711bdd

@matthewlipski
matthewlipski merged commit e870540 into main Aug 4, 2026
35 checks passed
@matthewlipski
matthewlipski deleted the parse-preserve-white-space branch August 4, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty paragraphs are being removed

2 participants